package com.ms.p2p.template.method;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ms.p2p.entity.content.ArticleCategory;
import com.ms.p2p.provider.ArticleCategoryProvider;
import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by xing_ on 2017/5/23.
 */
@Repository
public class ArticleCategoryMethod implements TemplateMethodModelEx {
    private static String prex = "";

    @Reference
    private ArticleCategoryProvider articleCategoryProvider;

    @Override
    public Object exec(List arguments) throws TemplateModelException {

        if (arguments != null && !arguments.isEmpty()  ) {

            String nid = String.valueOf(arguments.get(0));
           List<ArticleCategory>list = articleCategoryProvider.getlist();
            for(ArticleCategory category :list){
                if(nid.equals(category.getId()+"")){
                    return new SimpleScalar(category.getName());
                }
            }
        }

        return null;
    }
}
